﻿using Microsoft.Extensions.Options;
using TDengine.Data.Client;

namespace PHMEE.TDengineInfrastructure;

public class TDConnectionFactory : ITDConnectionFactory
{
    private readonly TDengineOptions _snapshotOptions;

    public TDConnectionFactory(IOptionsSnapshot<TDengineOptions> snapshotOptionsAccessor)
    {
        _snapshotOptions = snapshotOptionsAccessor.Value;
    }

    public TDengineConnection GetConnection()
    {
        var connectionString = _snapshotOptions.ConnectionString;

        var newConnection = new TDengineConnection(connectionString);
        newConnection.Open();

        return newConnection;
    }
}